<?php

class TestDataGeneration{
    public static function GenerateObjects(){
        self::GenerateObject();
        for($i = 0; $i <= 20; $i++){
            self::GenerateObject(1, 1);
        }
    }
    public static function GenerateObject($parentId = null, $pageParentId = null){
        $object = new Object();
        $object->name = "Test objects ".time();
        $object->description = "object body ".time();
        $object->objecttype_id = appcode\enum\ObjectType::GetByName(appcode\enum\ObjectType::Office);;
        $object->visibility_id = appcode\enum\Visibility::GetDefaultId();
        $object->manager_id = 1;
        $object->parent_id =  $parentId;
        $object->save();

        self::GeneratePages(appcode\enum\PageType::Object, $object->getIncremented(), $pageParentId);
    }

    public static function GeneratePages($type, $objectId = null, $parentId = null){
        $page = new Page();
        $page->linktitle = "Test page ".time();
        $page->title = "Test page title ".time();
        $page->body = "object body";
        $page->showinmenu = 1;
        $page->pagetype_id = appcode\enum\PageType::GetByName($type);
        $page->visibility_id = appcode\enum\Visibility::GetDefaultId();
        $page->language =  appcode\enum\Language::GetDefaultId();
        $page->parent_id =  $parentId;
        $page->object_id =  $objectId;
        $page->save();
    }

    public static function GenerateParty(){
        $party = new Party();
        $party->username = "test";
        $party->password = "you need to regenerate it";
        $party->visibility_id = appcode\enum\Visibility::GetDefaultId();
        $party->language = appcode\enum\Language::GetDefaultId();
        $party->save();

        $person = new Person();
        $person->firstname = "Peeter";
        $person->lastname = "Pauk";
        $person->personcode = "86456456";
        $person->party = $party;
        $person->save();

        $company = new Company();
        $company->name = "Minu Firma AS";
        $company->registrycode = "897987899";
        $company->party = $party;
        $company->save();
    }

    public static function GenerateEnums(){
        $enums = array(
            "Language",
            "PageType",
            "Visibility",
            "ObjectType",
            "ReadingType",
            "ServiceType",
            "DimensionType",
            "FileType",
            "AddressType",
            "SettingType",
            "RepresentationType",
            "ContractType",
        );

        foreach($enums as $enum){
            $enumClass = "appcode\\enum\\".$enum;
            $array = $enumClass::GetArray();
            echo $enum."<br/>";
            foreach($array as $item){
                $entity = new $enum();
                $entity->name = $item;
                $entity->save();
            }
        }
    }

    public static function GenerateTranslations(){
        $array = array(
            "TXT_MESSAGE_ERROR" => array("ee" => "Viga", "en" => "Error", "ru" => "Oшибка"),
            "TXT_MESSAGE_WARNING" => array("ee" => "Hoiatus", "en" => "Warning", "ru" => "Предупреждение"),
            "TXT_MESSAGE_INFO" => array("ee" => "Info", "en" => "Info", "ru" => "Nнформация"),
            "TXT_FORM_USERNAME" => array("ee" => "Kasutajanimi", "en" => "Username", "ru" => "Имя пользователя"),
            "TXT_FORM_PASSWORD" => array("ee" => "Parool", "en" => "Username", "ru" => "Честное слово"),
            "TXT_FORM_SUBMIT_LOGIN" => array("ee" => "Logi sisse", "en" => "Login", "ru" => "Войти"),
            "TXT_FORM_NAME" => array("ee" => "Nimi", "en" => "Name", "ru" => "Nмя"),
            "TXT_FOOTER_COPYRIGHT" => array("ee" => "Tehtud aastal 2012", "en" => "Made in year 2012", "ru" => "Сделано в 2012 году"),
            "TXT_BUTTON_LOGIN" => array("ee" => "Logi sisse", "en" => "Login", "ru" => "Войти"),
            "TXT_BUTTON_LOGOUT" => array("ee" => "Logi välja", "en" => "Logout", "ru" => "Выход"),
            "TXT_BUTTON_PROFILE" => array("ee" => "Profiil", "en" => "Profile", "ru" => "Профиль"),
            "TXT_FORM_PAGE_LINK_TITLE" => array("ee" => "Pealkiri menüüs", "en" => "Title in menu", "ru" => "Название в меню"),
            "TXT_FORM_PAGE_TITLE" => array("ee" => "Pealkiri", "en" => "Title", "ru" => "Название"),
            "TXT_FORM_PAGE_BODY" => array("ee" => "Sisu", "en" => "Body", "ru" => "Cодержание"),
            "TXT_FORM_PAGE_LANGUAGE" => array("ee" => "Regioon", "en" => "Region", "ru" => "Pегион"),
            "TXT_FORM_PAGE_PARENT" => array("ee" => "Ülem leht", "en" => "Parent", "ru" => "Pодитель"),
            "TXT_FORM_PAGE_SHOWINMENU" => array("ee" => "Kuva menüüs", "en" => "Show in menu", "ru" => "Показать в меню"),
            "TXT_FORM_SUBMIT_ADD" => array("ee" => "Lisa", "en" => "Add", "ru" => "Добавлять"),
            "TXT_CMS_CMS" => array("ee" => "Sisulehed", "en" => "CMS", "ru" => "CMS"),
            "TXT_CMS_CMS_ALL_PAGES" => array("ee" => "Kõik lehed", "en" => "All pages", "ru" => "Bсе"),
            "TXT_CMS_CMS_ADD_PAGE" => array("ee" => "Lisa leht", "en" => "Add page", "ru" => "Добавлять"),
            "TXT_CMS_USERS" => array("ee" => "Kasutajad", "en" => "Users", "ru" => "Пользователи"),
            "TXT_CMS_USERS_ALL_USERS" => array("ee" => "Kõik kasutajad", "en" => "All users", "ru" => "Bсе"),
            "TXT_CMS_USERS_ADD_USER" => array("ee" => "Lisa kasutaja", "en" => "Add user", "ru" => "Добавлять"),
            "TXT_CMS_COMPANIES" => array("ee" => "Ettevõtted", "en" => "Companies", "ru" => "Компании"),
            "TXT_CMS_COMPANIES_ALL_COMPANIES" => array("ee" => "Kõik ettevõtted", "en" => "All companies", "ru" => "Bсе"),
            "TXT_CMS_COMPANIES_ADD_COMPANY" => array("ee" => "Lisa ettevõte", "en" => "Add company", "ru" => "Добавлять"),
            "TXT_CMS_OBJECTS" => array("ee" => "Objektid", "en" => "Objects", "ru" => "Объекты"),
            "TXT_CMS_OBJECTS_ALL_OBJECTS" => array("ee" => "Kõik objektid", "en" => "All objects", "ru" => "Bсе"),
            "TXT_CMS_OBJECTS_ADD_OBJECT" => array("ee" => "Lisa objekt", "en" => "Add object", "ru" => "Добавлять"),
            "TXT_CMS_OBJECTS_DIMENSIONS" => array("ee" => "Dimensioonid", "en" => "Dimensions", "ru" => "Размеры"),
            "TXT_CMS_OBJECTS_READINGS" => array("ee" => "Näidud", "en" => "Readings", "ru" => "Чтения"),
            "TXT_INFO_LOGIN_REQUESTED" => array("ee" => "Palun identifitseeri ennast!", "en" => "Login requested!", "ru" => "Войти просил!"),
            "TXT_INFO_LOGIN_USER_SUCCESS" => array("ee" => "Teretulemast '{0}'!", "en" => "Welcome '{0}'!", "ru" => "Добро пожаловать '{0}'!"),
            "TXT_INFO_LOGGED_IN_ALREADY" => array("ee" => "Oled juba sisselogitud!", "en" => "You are logged in already!", "ru" => "Вы вошли в уже!"),
            "TXT_ERROR_LOGIN_USER_NOT_EXIST" => array("ee" => "Kasutajat '{0}' ei leitud!", "en" => "User '{0}' not found!", "ru" => "Пользователь '{0}' не найден!"),
            "TXT_ERROR_LOGIN_USER_IS_BLOCKED" => array("ee" => "Kasutajat '{0}' on blokeeritud!", "en" => "User '{0}' is blocked!", "ru" => "Пользователь '{0}' заблокирован!"),
            "TXT_ERROR_LOGIN_USER_WRONG_PASSWORD" => array("ee" => "Sisestasite vale parooli kasutaja '{0}' jaoks!", "en" => "Wrong password for user '{0}'!", "ru" => "Неверный пароль для пользователя '{0}'!"),
            "TXT_ERROR_FIELD_IS_MANDATORY" => array("ee" => "Väli '{0}' on kohustuslik!", "en" => "Field '{0}' is mandatory!", "ru" => "Поле '{0}' является обязательным!"),
            "TXT_PAGE_TITLE_MY_DETAILS" => array("ee" => "Minu profiil", "en" => "My profile", "ru" => "Мой профиль"),
            "TXT_PAGE_TITLE_LOGIN" => array("ee" => "Logi sisse", "en" => "Login", "ru" => "Войти"),
            "TXT_PAGE_TITLE_LOGOUT" => array("ee" => "Logi välja", "en" => "Logout", "ru" => "Выход"),

            "TXT_BREADCRUMB_HOME" => array("ee" => "Pealeht", "en" => "Frontpage", "ru" => "Главная"),
            "TXT_CTRL_Objects_Index_TITLE" => array("ee" => "Objektid", "en" => "Objects", "ru" => "Объекты"),
            "TXT_CTRL_Objects_Add_TITLE" => array("ee" => "Lisa objekt", "en" => "Add object", "ru" => "Добавить объект"),
            "TXT_CTRL_Objects_Dimensions_TITLE" => array("ee" => "Dimensioonid", "en" => "Dimensions", "ru" => "Размеры"),
            "TXT_CTRL_Objects_Readings_TITLE" => array("ee" => "Näidud", "en" => "Readings", "ru" => "Чтения"),
            "TXT_CTRL_Users_Index_TITLE" => array("ee" => "Kasutaja", "en" => "User", "ru" => "Пользователь"),
            "TXT_CTRL_Users_Login_TITLE" => array("ee" => "Logi sisse", "en" => "Login", "ru" => "Войти"),
            "TXT_CTRL_Users_Add_TITLE" => array("ee" => "Lisa kasutaja", "en" => "Add user", "ru" => "Добавить пользователя"),
            "TXT_CTRL_Cms_Index_TITLE" => array("ee" => "Sisulehed", "en" => "CMS", "ru" => "CMS"),
            "TXT_CTRL_Cms_Add_TITLE" => array("ee" => "Lisa sisuleht", "en" => "Add page", "ru" => "Добавить страницу"),
            "TXT_CTRL_Companies_Index_TITLE" => array("ee" => "Kõik ettevõtted", "en" => "All companies", "ru" => "Все компании"),
            "TXT_CTRL_Companies_Add_TITLE" => array("ee" => "Lisa ettevõte", "en" => "Add compay", "ru" => "Добавить kомпай"),
        );

        echo "Translations: <br/>";
        foreach($array as $key => $value){
            echo $key."<br/>";
            foreach($value as $k => $v){
                $translation = new Translation();
                $translation->key = $key;
                $translation->value = utf8_encode($v);
                $translation->language = $k;
                $translation->visibility_id = appcode\enum\Visibility::GetDefaultId();
                $translation->save();
            }
        }
    }
}
